package org.backend.canteenbackend.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.backend.canteenbackend.entity.Account;
import org.backend.canteenbackend.persistence.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;

public class UniqueUsernameValidator implements ConstraintValidator<UniqueUsername, String> {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public void initialize(UniqueUsername constraintAnnotation) {
    }

    @Override
    public boolean isValid(String username, ConstraintValidatorContext context) {
        Account account=accountMapper.selectById(username);
        return account.equals(null);
    }
}